package ooday03;
/** 引用类型数组的演示 */
public class RafArrayDemo {
    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",1,"黑");
        dogs[1] = new Dog("小白",2,"白");
        dogs[2] = new Dog("小红",3,"红");
        System.out.println(dogs[0].name);//输出第一只狗狗的名字
        dogs[1].age=4;//修改第二只狗狗的年龄为4
        dogs[2].swim();//第三只狗狗在游泳
        for (int i=0;i<dogs.length;i++){//遍历dogs数组
            System.out.println(dogs[i].name);//输出每只狗狗的名字
            dogs[i].eat();//狗狗在吃饭
        }


        Chick[] chicks = new Chick[3];
        chicks[0] = new Chick("小金",2,"金");
        chicks[1] = new Chick("大红",6,"红");
        for (int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].eat();
        }

        Fish[] fish = new Fish[2];// 默认值为 null
        fish[0] = new Fish("小灰",9,"灰");
        fish[1] = new Fish("小黄",8,"黄");
        for (int i=0;i<fish.length;i++){
            System.out.println(fish[i].name);
            fish[i].swim();
        }



        /*
        //声明Dog型数组dogs,包含三个元素，都是Dog型，默认值为null
        Dog[] dogs = new Dog[3];

        //声明Chick型数组chicks,包含三个元素,都是Chick型，默认值为null
        Chick[] chicks = new Chick[3];

        //声明Fish型数组fish，包含三个元素，都是Fish型，默认值为null
        Fish[] fish = new Fish[3];

         */
    }
}
